home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / pcfig4th.zip / CODE.SCR < prev    next >
Text File  |  1985-04-23  |  5KB  |  1 lines

  1. Examples of FORTH Assembler code:                                                                                               The following screens contain some handy words written in the   FORTH 8086 Assembler.                                                                                                           Using the assembler to define these words gains you speed, but  costs you space: the assembler (about 6K) has to be there to    assemble the words, and then you can't get rid of it.                                                                           Therefore, the use of the examples is entirely up to you...                                                                                                                                                                                                                                                                                                                                                                                                     ( Assembler examples, bit manipulation: << >> ~ )                                                                               CODE <<   ( n1 n2 -- n3 ;shift n1 left n2 times )                       CX POP   AX POP   AX, CX SHL   AX PUSH  NEXT                                                                            CODE >>   ( n1 n2 -- n3 ;shift n1 right n2 places )                     CX POP   AX POP   AX, CX SHR   AX PUSH  NEXT                                                                            CODE ~   ( n -- ~n ;returns the one's complement of n )                 AX POP   AX NOT   AX PUSH  NEXT                                                                                                                                                                                                                                                                                                                                                                                                                         ( assembler examples: PICK, <CMOVE )                                                                                            CODE PICK  ( n -- m ;copy the nth stack item to the top, top=0 )        DI POP   DI, 1 SHL  ( index*2 )                                 BP PUSH  BP, SP MOV   AX, 2 [BP+DI] MOV ( get data )            BP POP   AX PUSH  NEXT                                                                                                  CODE <CMOVE  ( from to len -- ;backward CMOVE )                         BX, SI MOV   CX POP    DI POP ( to)   SI POP ( from)            DI, CX ADD   SI, CX ADD  ( move from the ends )                 DI DEC       SI DEC                                             DS PUSH      ES POP  ( all in one segment )                     STD ( count down )   REP  BYTE MOVS ( move it )                 CLD   SI, BX MOV    NEXT                                                                                                                                                                ( assembler examples: ROLL )                                    CODE ROLL   ( n -- ;roll the top n stack items, nth to top )                ( should check for 1<n<100 or so )                          CX POP                                                          CX DEC   CX, 1 SHL  ( byte count )                              BX, CX MOV  ( index ) DI, SP MOV  ( base )                      AX, [BX+DI] MOV  ( save nth element )                           BX, SI MOV  ( save IP )                                         DI, CX ADD  SI, DI MOV  SI, # 2 SUB                             CX, 1 SHR ( word count )                                        STD  REP  WORD MOVS CLD ( move top n-1 stack elements )         SI, BX MOV  BX POP  AX PUSH                                   NEXT                                                                                                                                                                                                                                                      ( assembler examples: S->D  )                                                                                                   CODE S->D  ( n -- d; convert 16-bit to 32-bit signed number )           AX POP  CWD   AX PUSH  DX PUSH  NEXT                                                                                    ;S